package com.api.gbhg.liubing.dao;

import com.api.gbhg.zengping.dao.PropertyManagementCostDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.conn.RecordSetTrans;

/**
 * @author : liubing
 * @date :  2021/1/8 14:54
 */
public class EndowmentInsuranceDao {
    public static final Logger LOGGER= LoggerFactory.getLogger(PropertyManagementCostDao.class);
    //查看  养老保险 主表数据
    public RecordSetTrans getMainTable(String requestId){
        RecordSetTrans rts=new RecordSetTrans();
        StringBuffer sb=new StringBuffer();
        String sql ="select v.lcjlsqjlid, v.lcid,v.xmmin,v.sbdw,v.sbks,v.jbr,v.yszje,h.zfcgyswy,h.hwgz,h.gc,h.fw,h.xecg,h.requestId from uf_jingfei_version v " +
                "INNER JOIN uf_hgylbxjfjfxqb h on v.lcjlsqjlid =h.requestId where h.requestId in (" + requestId +")";
        sb.append(sql);
        try {
//            if(status.equals("3")){
//                sb.append(" AND lcztz="+status);
//            }else {
//                sb.append(" AND lcztz<> 3");
//            }
//            //通过分页公式计算下一页在哪一行开始
//            //如1，10，1-1 = 0，那第一条开始显示下面十条，第一页
//            //如2，10，(2-1)乘以10 = 10，那就是第十条开始显示下面十条，第二页
//            // 判断是mysql 还是sqlserver
//            pageNum=(pageNum-1)*pageSize;
//            if("sqlserver".equals(rts.getDBType())){
//                sb.append(" order by v.Id offset "+pageNum+" rows fetch next "+pageSize+" rows only");
//            }else if("mysql".equals(rts.getDBType())){
//                sb.append(" LIMIT "+pageNum+","+pageSize+"");
//            }
            LOGGER.info("养老保险主表sql:--->"+sb.toString());
            rts.executeQuery(sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return rts;
    }
    //获取数据条数
    public int getMainTableCount(String status){
        RecordSet rs = new RecordSet();
        String StrSQL ="select COUNT(1)AS num from uf_jingfei_version v INNER JOIN uf_hgylbxjfjfxqb j on v.lcjlsqjlid =j.requestId where 1=1";
        if(status.equals("3")){
            StrSQL=StrSQL+(" AND lcztz="+status);
        }else {
            StrSQL=StrSQL+(" AND lcztz<> 3");
        }
        LOGGER.info("养老保险总条数sql:--->"+StrSQL);
        rs.executeQuery(StrSQL);
        rs.next();
        return rs.getInt("num");
    }
    //查看 明细表数据
    public RecordSet getDetailedTable(String requestid, int table){
        RecordSet rs = new RecordSet();
        String StrSQL="";
        if (table==1){
            StrSQL = "select * from uf_hgylbxjfjfxqb_dt1 where mainid="+"(select id from uf_hgylbxjfjfxqb where requestid=" + requestid+")"; //获取明细条1
        }else if (table==2){
            StrSQL = "select * from uf_hgylbxjfjfxqb_dt2 where mainid="+"(select id from uf_hgylbxjfjfxqb where requestid=" + requestid+")"; //获取明细条2
        }
        LOGGER.info("养老保险明细表sql:--->"+StrSQL);
        rs.executeQuery(StrSQL);
        return rs;
    }

}
